package 设计模式.创建型模式.demo03生成器模式.components;

import lombok.AllArgsConstructor;
import lombok.Data;

/**
 * @author: 王富贵
 * @description: 引擎类
 * @createTime: 2022/11/07 14:16
 */
@Data
@AllArgsConstructor
public class Engine {
    private final double volume;
    private double mileage;
    private boolean started;

    public Engine(double volume, double mileage) {
        this.volume = volume;
        this.mileage = mileage;
    }

    public void on() {
        started = true;
    }

    public void off() {
        started = false;
    }

    public boolean isStarted() {
        return started;
    }

    public void go(double mileage) {
        if (started) {
            this.mileage += mileage;
        } else {
            System.err.println("Cannot go(), you must start engine first!");
        }
    }
}
